<template>
    <div @click="onAdd">
        添加路由
    </div>
</template>

<script>
import lazyRoute from '@/utils/menuLoad.js'
import XEUtils from "xe-utils";
export default {
    data() {
        return {
            routeData: [{

                path: "/video11111",
                name: "video11111",
                component: "video/index"

            },
            ]
        }
    },
    methods: {
        //递归过滤树
        filterTree(treeArr) {

            function findItem(arr) {
                let res = arr.filter(item => {
                    if (item.children && item.children.length > 0) {//isShow为true且有子集递归
                        item.children = findItem(item.children)
                    }

                    item.component = lazyRoute(item.component)


                    return item
                })
                return res
            }
            return findItem(treeArr)
        },


        onAdd() {
            console.log(this.routeData);
            this.routeData.forEach(item=>{
                if (item.parentId == '-1') {
                    item.component='Layout'
                    item.path='/'
                }
            })
            let routeData = this.filterTree(this.routeData)
            console.log(routeData)
            this.$router.addRoutes(routeData)
            // this.$router.options.routes=routeData
            console.log(this.$router.options.routes);
        }
    }
}
</script>

<style>
</style>